<template>
  <div class="balance-log-con">
    <div class="table">
      <div class="thead">
        <div class="tr">
          <div class="td">类型</div>
          <div class="td">收支</div>
        </div>
      </div>
      <div class="tbody"
           v-if="balanceLog.length>0">
        <van-list v-model="loading"
                  :finished="finished"
                  :error.sync="error"
                  error-text="请求失败，点击重新加载"
                  finished-text=""
                  @load="onLoad">
          <div class="tr log-tr"
               v-for="(balanceItem,index) in balanceLog"
               :key="index">
            <div class="td">
              <div class="remark">{{balanceItem.remark}}</div>
              <div class="time">{{balanceItem.create_time}}</div>
            </div>
            <div class="td num" :class="balanceItem.change_num>0?'add':''">{{balanceItem.change_num}}</div>
          </div>
        </van-list>
      </div>
      <div v-else>
        <no-data :noData="noData"></no-data>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import noData from '@/components/noData/index'
// import { Grid, GridItem } from 'vant'
// Vue.use(Grid).use(GridItem)
import { getBalanceTxLog } from '@/api/user/member/memberApi'

export default Vue.extend({
  name: 'index',
  components: {
    noData
  },
  created() {
    this.init()
  },
  data() {
    return {
      noData: {
        width: '184px',
        txtMarginTop: '-30px',
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no_tx_log.png',
        text: '暂无数据'
      },
      page: 1,
      balanceLog: [],
      error: false,
      loading: false,
      finished: false
    }
  },
  methods: {
    init() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)
      // console.log('init1')
      this.page = 1
      this.finished = false
      this.balanceLog = []
      this.onLoad()
    },
    onLoad() {
      if (this.finished) { return false }
      const params = {
        act_type: false,
        p: this.page
      }
      getBalanceTxLog(params)
        .then(res => {
          this.loading = false
          this.$loadingWrap.close()
          if (res.status == 1) {
            const resData = res.data
            this.balanceLog.push(...resData.balance_change)
            if (resData.balance_change.length < 10) {
              this.finished = true
            } else {
              this.page++
            }
          } else {
            this.$Error(res.msg)
          }
        })
        .catch(() => {
          this.error = true
        })
      // 11
      // const data = { p: this.p }
      // getLetter(data)
      //   .then(res => {
      //     this.loading = false
      //     this.$loadingWrap.close()
      //     if (res.status == 1) {
      //       this.lists.push(...res.data)
      //       this.p = this.p + 1
      //     } else {
      //       this.finished = true
      //     }
      //   })
      //   .catch(() => {
      //     this.error = true
      //   })
    }
  }
})
</script>

<style lang="scss">
.balance-log-con {
  margin-top:30px;
  // margin: 0 20px;
  text-align: center;
  .no-data {
    img {
      width: 49% !important;
    }
  }
  .tr {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    align-items: center;
    border-bottom: 2px solid #EEEEEE;
    padding:0 24px;
    &:last-child {
      border-bottom: 0;
    }
    .td {
      // flex-basis: 33.3333%;
      // flex-basis: 1;
      &:nth-child(1) {
        flex: 1;
        text-align:left;
      }
      &:nth-child(2) {
        width:30%;
        text-align:right;
      }
      // &:nth-child(3) {
      //   flex: 2;
      // }
      &.no-data {
        color: #666;
      }
    }
  }
  .thead {
    border-radius: 10px;
    background: #F8F8F8;
    line-height: 86px;
    .td {
      font-size: 24px;
      font-weight: bold;
      color: #333333;
    }
  }
  .tbody {
    .td {
      // line-height: 100px;
      line-height: 1.6;
      padding:30px 0;
      .remark{
        font-size:28px;
        font-weight: bold;
      }
      .time{
        color:#999;
      }
      &.num{
        font-size: 32px;
        font-weight: bold;
        &.add{
          color: #fd2049;
        }
      }
    }
  }
}
</style>
